package week4;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Josephus {
    // 继续绕圈消灭第n个士兵
    public static void main(String[] args)
    {
        int numPeople, skip, targetIndex;
        List<String> list = new ArrayList<String>();
        Scanner in = new Scanner(System.in);

        // 得到初始值
        System.out.print("Enter the number of soldiers: ");
        numPeople = in.nextInt();
        in.nextLine();

        // 第几个跳过
        System.out.print("Enter the number of soldiers to skip: ");
        skip = in.nextInt();

        // 读取最初列表
        for (int count = 1; count <= numPeople; count++)
        {
            list.add("Soldier " + count);
        }

        targetIndex = skip;
        System.out.println("The order is: ");

        // 把列表看成一个圆，进行删除，知道列表为空
        while (!list.isEmpty())
        {
            System.out.println(list.remove(targetIndex));
            if (list.size() > 0)
                targetIndex = (targetIndex + skip) % list.size();
        }
    }
}
